<%@ page language="java" contentType="text/html; charset=UTF-8"
	pageEncoding="UTF-8"%>
<%@ taglib prefix="c" uri="http://java.sun.com/jsp/jstl/core"%>
<!DOCTYPE html PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN" "http://www.w3.org/TR/html4/loose.dtd">
<html>
<head>
<meta http-equiv="Content-Type" content="text/html; charset=UTF-8">
<title>器械入库</title>
<link rel="stylesheet" type="text/css"
	href="<c:url value="/css/themes/default/easyui.css"/>">
<link rel="stylesheet" type="text/css"
	href="<c:url value="/css/themes/icon.css"/>">
<script type="text/javascript" src="<c:url value="/js/jquery.min.js"/>"></script>
<script type="text/javascript"
	src="<c:url value="/js/jquery.easyui.min.js"/>"></script>
<script type="text/javascript"
	src="<c:url value="/js/easyui-lang-zh_CN.js"/>"></script>
</head>

<body>
<style type="text/css">
	*{
		font-size:12px;
	}
	#InStorageInfo{
		width:100%;
		overflow: hidden;
	}
	li{
		float: left;
		list-style: none;
	}
</style>
<script type="text/javascript">
$(function(){
	//采购器械自动赋值
	$('#qxcgrk').combogrid({
		onChange: function (newValue, oldValue) {
			var thpcpName=$("#qxcgrk").combogrid("getText");
			$.getJSON("selectHisPurchaseBycpName", {"cpName": thpcpName}, function(data){
				$('#rkcgph').textbox('setValue',data.cgBatchnumber);
				$('#rkcgdw').textbox('setValue',data.cgUnit);
				$('#rkcgdj').textbox('setValue',data.cgPrice);
				$('#rkcgsl').textbox('setValue',data.cgNumber);
				$('#rkcgzje').textbox('setValue',data.cgTotalprice);
				$('#rkcgbz').textbox('setValue',data.cgRemarks);
				$('#rksl').numberspinner('setValue',$('#rkcgsl').textbox('getValue'));
			});
		}
	});
	
	//采购产品加入临时入库表
	$('#add-rkData').linkbutton({
		onClick : function() {
			var rkckID=$('#rkckID').combogrid('getText');
			var rkDate=$('#rkDate').datebox('getText');
			var rkType=$('#rkType').combobox('getValue');
			var rkFzr=$('#rkFzr').combogrid('getText');
			var rkqxcgID=$('#qxcgrk').combogrid('getValue');
			var rkqxcgName=$('#qxcgrk').combogrid('getText');
			var rkcgzje=$('#rkcgzje').textbox('getValue');
			var rkcgsl=$('#rkcgsl').textbox('getValue');
			var rkcgdw=$('#rkcgdw').textbox('getValue');
			var rkcgdj=$('#rkcgdj').textbox('getValue');
			var rkcgph=$('#rkcgph').textbox('getValue');
			var rksl=$('#rksl').numberspinner('getValue');
			var rkcgbz=$('#rkcgbz').textbox('getValue');
			var a=0;
			var rows=$('#thpqxrk').datagrid('getRows');
			if(rkckID=='' || rkDate=='' || rkType=='' || rkFzr=='' || rkqxcgName=='' || rksl=='' ){
				$.messager.alert("温馨提示", "请把数据填充完整!",'info');
			}else{
				$('#thpqxrk').datagrid('appendRow', {
					'ckNo' : rkckID,
					'hisInstorages.cgNo' : rkqxcgID,
					'hisInstorages.rkName' : rkqxcgName,
					'cgNumber' : rkcgsl,
					'cgUnit' : rkcgdw,
					'cgPrice' : rkcgdj,
					'cgTotalprice' : rkcgzje,
					'cgBatchnumber' : rkcgph,
					'hisInstorages.rkType' : rkType,
					'ygNo' : rkFzr,
					'hisInstorages.rkTime' : rkDate,
					'hisInstorages.rkNumber' : rksl,
					'cgRemarks' : rkcgbz
				});
				$('#rkAllqx').form("clear");
			}
		}
	});
	
	//入库
	$('#submit-thprk').linkbutton({
		onClick : function(){
			//将datagrid中的数据行保存到隐式表单域中
			//1、获取新增的数据行
			var rows = $('#thpqxrk').datagrid('getChanges');
			//为每一行生成对应的隐藏表单域
			var today='${InstorageId }'*1;
			var rkckID=$('#rkckID').combogrid('getValue');
			var ff_thpHisInStorage=$('#ff_thpHisInStorage');
			var rkFzr=$('#rkFzr').combogrid('getValue');
			for(var i = 0; i < rows.length; i ++){
				$("<input type='hidden' x='y'>").attr("name",
						"hisInstorages[" + i + '].rcNo').val(
								today+i).appendTo(ff_thpHisInStorage);
				$("<input type='hidden' x='y'>").attr("name",
						"hisInstorages[" + i + '].ckNo').val(
								rkckID).appendTo(ff_thpHisInStorage);
				$("<input type='hidden' x='y'>").attr("name",
						"hisInstorages[" + i + '].ygNo').val(
								rkFzr).appendTo(ff_thpHisInStorage);
				generateHidden(rows[i], "rkName", i);
				generateHidden(rows[i], "cgNo", i);
				generateHidden(rows[i], "rkNumber", i);
				generateHidden(rows[i], "rkTime", i);
				generateHidden(rows[i], "rkType", i);
			}
			//提交表单
			if(rows.length != 0){
				$('#ff_thpHisInStorage').form('submit', {
					success: function(v){
						$(":hidden[x='y']").remove();
						$('#thpqxcg').datagrid('loadData', { total: 0, rows: [] });
						//alert(v);
						var json = eval("(" + v + ")");
						$.messager.alert('温馨提示', "入库"+json.reason);
						$('#ff_thpHisInStorage').form("clear");
						$("#win-QiXieInstorage").window("close");
					}
				});
			}
		}
	});
	function generateHidden(row, name, i) {
		var ff_thpHisInStorage = $("#ff_thpHisInStorage");
		$("<input type='hidden' x='y'>").attr("name",
				"hisInstorages[" + i + '].'  + name).val(
				row['hisInstorages.'+name]).appendTo(ff_thpHisInStorage);
	}
});
</script>
	<!-- 器械入库 -->
	<!-- <div id="win-QiXieInstorage" class="easyui-window" title="器械入库" data-options="collapsible:false,
		minimizable:false,
		maximizable:false,
		modal:true,
		iconCls:'icon-storage'"
		style="width: 806px; height: 500px;"> -->
		<form id="ff_thpHisInStorage" action="QiXieStorage" method="post">
			<div id="InStorageContent">
				<div id="InStorageInfo" style="background-color: rgb(236,243,255)">
					<ul>
						<li style="margin:0px 100px 5px 0px;">入库单号&nbsp;<input value="${InstorageId }" class="easyui-textbox" data-options="width: 150" readonly="readonly"></li>
						<li style="margin:0px 0px 5px 0px;">仓库&nbsp;<select id="rkckID" class="easyui-combogrid" data-options="width: 150,
							url:'selectAllHisWarehouse',
							idField:'ckNo',
							panelHeight:'auto',
							textField:'ckName',
							columns:[[
					            {field:'ckName',title:'仓库名称',width:'146px'}
							]]
							"></select></li>
						<li style="margin:0px 0px 5px 100px;">入库日期&nbsp;<input id="rkDate" class="easyui-datebox" data-options="width: 100"></li>
						<li style="margin:0px 0px 20px 0px;">入库类型&nbsp;<select id="rkType" class="easyui-combobox" data-options="width: 150,panelHeight:'auto'">
							<option value="器械" selected="selected">器械</option><option value="耗材">耗材</option>
							<option value="中药">中药</option><option value="西药">西药</option></select></li>
						<li style="margin:0px 0px 20px 391px;">负责人&nbsp;<select id="rkFzr" class="easyui-combogrid" data-options="width: 100,
							url:'findAllEmployee',
							idField:'ygNo',
							panelHeight:200,
							panelWidth:225,
							textField:'ygName',
							columns:[[
					            {field:'ygName',title:'姓名',width:50},
					            {field:'bmName',title:'部门',width:75},
					            {field:'ygPost',title:'职务',width:92}
							]]"></select></li>
					</ul>
				</div>
				<div style="border-top:1px solid #95B8e7;width:100%;height:340px;overflow: hidden;">
				        <div>
				        	<div id="rkAllqx" style="overflow: hidden;">
				        		<ul>
									<li id="" style="margin:10px 30px 10px 0px;">器械&nbsp;<select id="qxcgrk" class="easyui-combogrid" data-options="width: 150,
										url:'selectHisPurchaseAndCheckAcceptData',
										idField:'cgNo',
										panelHeight:'auto',
										textField:'cpName',
										columns:[[
								            {field:'cpName',title:'采购器械名称',width:'146px'}
										]]
										"></select></li>
									<li id="" style="margin:10px 40px 10px 0px;">单价&nbsp;<input id="rkcgdj" class="easyui-numberbox" readonly="readonly" data-options="width: 100,precision:2"></li>
									<li id="" style="margin:10px 0px 10px 0px;">采购数量&nbsp;<input id="rkcgsl" readonly="readonly" class="easyui-numberbox" data-options="width: 100"></li>
									<li id="" style="margin:10px 0px 10px 40px;">总金额&nbsp;<input id="rkcgzje" class="easyui-numberbox" readonly="readonly" data-options="width: 100,precision:2"></li>
									<li id="" style="margin:0px 30px 10px 0px;">批号&nbsp;<input id="rkcgph" class="easyui-textbox" readonly="readonly" data-options="width: 150"></li>
									<li id="" style="margin:0px 40px 10px 0px;">单位&nbsp;<input id="rkcgdw" class="easyui-textbox" readonly="readonly" data-options="width: 100"></li>
									<li id="" style="margin:0px 0px 10px 0px;">入库数量&nbsp;<input id="rksl" class="easyui-numberspinner" data-options="width: 100"></li>
									<li id="" style="margin:0px 50px 10px 0px;">备注&nbsp;<input id="rkcgbz" class="easyui-textbox" data-options="width: 500"></li>
									<li id="" style="margin:0px 0px 10px 48px;"><a id="add-rkData" class="easyui-linkbutton" style="width:80px;">加入</a></li>
								</ul>
				        	</div>
				        	<div style="border-bottom:1px #95B8e7 solid;height:210px;">
								<table id="thpqxrk" class="easyui-datagrid"
								data-options="
									fitColumns:true,
									fit:true,
									singleSelect: true,
									rownumbers: true,
									panelHeight: '100',
									toolbar: '#qxInStoragetb',
									border:false
									">
								<thead>
									<tr>
										<th data-options="field:'ckNo',width:'10%',editor:'textbox'">仓库</th>
										<th data-options="field:'hisInstorages.cgNo',width:'15%',editor:'numberbox'">采购单号</th>
										<th data-options="field:'hisInstorages.rkName',width:'15%',editor:'numberbox'">器械名称</th>
										<th data-options="field:'cgNumber',width:'10%',editor:'numberbox'">采购数量</th>
										<th data-options="field:'cgUnit',width:'8%',editor:{
											type:'combobox',
											options:{
												valueField:'label',
												textField:'value',
												panelHeight: 'auto',
												data: [{label:'箱',value:'箱'},{label:'盒',value:'盒'},
												{label:'个',value:'个'},{label:'件',value:'件'},
												{label:'卷',value:'卷'},{label:'斤',value:'斤'},
												{label:'包',value:'包'}]}
											}">单位</th>
										<th data-options="field:'cgPrice',width:'8%',editor:'numberbox'">单价</th>
										<th data-options="field:'cgTotalprice',width:'10%',editor:'numberbox'">采购总金额</th>
										<th data-options="field:'cgBatchnumber',width:'15%',editor:'textbox'">批号</th>
										<th data-options="field:'hisInstorages.rkType',width:'10%',editor:'numberbox'">入库类型</th>
										<th data-options="field:'ygNo',width:'10%',editor:'numberbox'">负责人</th>
										<th data-options="field:'hisInstorages.rkTime',width:'12%',editor:'numberbox'">入库日期</th>
										<th data-options="field:'hisInstorages.rkNumber',width:'10%',editor:'numberbox'">入库数量</th>
										<th data-options="field:'cgRemarks',width:'20%',editor:'textbox'">备注</th>
									</tr>
								</thead>
							</table>
							<div id="qxInStoragetb" style="height: auto;padding-left: 30px;">
								<a href="javascript:void(0)" class="easyui-linkbutton"
								data-options="iconCls:'icon-add',plain:true">添加一行</a>
								<a href="javascript:void(0)" class="easyui-linkbutton"
									data-options="iconCls:'icon-remove',plain:true">移除一行</a>
								<a href="javascript:void(0)" class="easyui-linkbutton" data-options="iconCls:'icon-ok',plain:true">应用</a>
								<a href="javascript:void(0)" class="easyui-linkbutton"
									data-options="iconCls:'icon-undo',plain:true">撤销</a>
							</div>
				        	</div>
				        </div>
				    </div>
				    <div style="margin:5px 5px 0px 0px;text-align: right;">
						<a id="submit-thprk" class="easyui-linkbutton" data-options="iconCls:'icon-ok'">入库</a>
					</div>
				</div>
			</form>
	<!-- </div> -->
</body>
</html>